package com.xwdeshj.controller;

import com.xwdeshj.utils.CookieUtils;
import com.xwdeshj.utils.IMoocExceptionHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by BKWJA on 2018/11/19.
 * 页面直接跳转
 */
//排除当前的类，不做swagger 忽略该 Controller，指不对当前类做扫描
@ApiIgnore

@Controller
@CrossOrigin(allowCredentials = "true")
public class IntercepterController extends IMoocExceptionHandler {

    /**
     * 默认页面跳转
     * @return
     */
    @RequestMapping("/")
    public String gologin(){
        return "login";
    }

    /**
     * 一级目录页面跳转
     * @param page
     * @return
     */
    @RequestMapping("/{page}")
    public String index(@PathVariable(value = "page") String page){
        return page;
    }

    /**
     * 多级目录页面跳转
     * @param parent
     * @param page
     * @return
     */
    @RequestMapping("/{parent}/{page}.html")
    public String parentindex(@PathVariable(value = "parent") String parent,
                              @PathVariable(value = "page") String page){
        String url = "";
        if(page == null || page == ""){
            url = parent;
        }else {
            url = parent+"/"+page;
        }
        return url;
    }


    //退出
    @RequestMapping("loginout")
    public String loginout(HttpServletRequest request, HttpServletResponse response){
        //删除cookie
        CookieUtils.deleteCookie(request,response,"token");
        CookieUtils.deleteCookie(request,response,"uid_encryptid");
        CookieUtils.deleteCookie(request,response,"admin_role");
        return "login";
    }


}
